unit PesquisaContaContabil_rapida;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, StdCtrls, Mask, ToolEdit, DB, ExtCtrls;

type
  TFesquisaContaContabil_rapida = class(TForm)
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    edPesquisa: TComboEdit;
    DBGrid1: TDBGrid;
    dsPesquisa: TDataSource;
    Panel1: TPanel;
    procedure edPesquisaChange(Sender: TObject);
    procedure edPesquisaButtonClick(Sender: TObject);
    procedure edPesquisaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1CellClick(Column: TColumn);
    procedure DBGrid1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FesquisaContaContabil_rapida: TFesquisaContaContabil_rapida;

implementation

uses UGestao, UDmFinanceiro, UEstruturaPlano, CadastroProdutos;

{$R *.dfm}

procedure TFesquisaContaContabil_rapida.edPesquisaChange(Sender: TObject);
begin
  if RadioButton1.Checked then
  begin
    if dsPesquisa.DataSet.Locate('PLANOCONT_CODIGOCONTABIL',edPesquisa.Text,[LoPartialKey, loCaseInsensitive]) then
      Panel1.Caption := dsPesquisa.DataSet.FieldByName('PLANOCONT_CODIGOCONTABIL').AsString + ' - ' +
                        dsPesquisa.DataSet.FieldByName('PLANOCONT_DESCRICAO').AsString
    else
      Panel1.Caption := '';

  end else begin
    if dsPesquisa.DataSet.Locate('PLANOCONT_DESCRICAO',edPesquisa.Text,[LoPartialKey, loCaseInsensitive]) then
      Panel1.Caption := dsPesquisa.DataSet.FieldByName('PLANOCONT_CODIGOCONTABIL').AsString + ' - ' +
                        dsPesquisa.DataSet.FieldByName('PLANOCONT_DESCRICAO').AsString
    else
      Panel1.Caption := '';

  end;

  Self.Close;

end;

procedure TFesquisaContaContabil_rapida.edPesquisaButtonClick(
  Sender: TObject);
begin
  if FEstruturaPlano <> nil then
  begin
    FEstruturaPlano.ContaContabil.LookupValue := dsPesquisa.DataSet.FieldByName('PLANOCONT_CODIGO').AsString;
    self.Close;
  end;

  if FCadastroProdutos <> nil then
  begin

    if FCadastroProdutos.DBLCBContaContabil.Focused then
      FCadastroProdutos.dSProduto.DataSet.FieldByName('PROD_CONTACONTABIL').AsVariant := dsPesquisa.DataSet.FieldByName('PLANOCONT_CODIGO').AsString;

    self.Close;
  end;

end;

procedure TFesquisaContaContabil_rapida.edPesquisaKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key = vk_return then
    edPesquisa.Button.Click;

end;

procedure TFesquisaContaContabil_rapida.DBGrid1CellClick(Column: TColumn);
begin
  Panel1.Caption := dsPesquisa.DataSet.FieldByName('PLANOCONT_CODIGOCONTABIL').AsString + ' - ' +
                    dsPesquisa.DataSet.FieldByName('PLANOCONT_DESCRICAO').AsString

end;

procedure TFesquisaContaContabil_rapida.DBGrid1DblClick(Sender: TObject);
begin

  edPesquisa.Button.Click;

end;

end.
